package com.study.samsung.Control.htControl;

import com.study.samsung.Entity.htEntity.Admin;
import com.study.samsung.Service.htService.UserService;
import com.study.samsung.Utils.BaseServlet;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;

@WebServlet("/htlogin")
public class LoginServlet extends BaseServlet {
    UserService ad = new UserService();
    @Override
    public String excute(HttpServletRequest request, HttpServletResponse response) throws Exception {
        return "f:htjsp/login";
    }

    public void selectByLogin(HttpServletRequest request, HttpServletResponse response) throws Exception {
        response.setCharacterEncoding("utf-8");
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        PrintWriter writer = response.getWriter();
        Admin admin = new Admin();
        admin.setAdminaccount(username);
        admin.setAdminpwd(password);

        Integer result = ad.selectByLogin(admin);
        if (result>0){
            session.setAttribute("admin",admin);
            writer.print(1);
        }else {
            writer.print(result);
        }
        writer.close();
    }
}
